********Table 2 - Indonesia ********

*Load data and create differences
cd "$reploc/data/created_data"
use indo_full, clear

sort pidlink ifls
drop if ifls==.
keep if panel==1

*Normalize monetary variables
gen assets_ia_use=assets_ia/1000000
gen income_ia_use=income_ia/1000000
gen savingnettotal_ia_use=savingnettotal_ia/1000000

keep rbuc* gambleaverse ifls pidlink inflation imp_age panel biryear_impl grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* birprov_impl income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh dis_*_hh disbad_*_hh

reshape wide rbuc* gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh dis_*_hh disbad_*_hh, i(pidlink) j(ifls)


local varlist1 rbuc rbucB rbuc_nga rbuc_garefined rbucgaref1a rbucgaref2a rbucgaref3a rbucgaref4a gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3  married hhsize hhsize_sq income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh 


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'5-`var'4
}


foreach var of varlist Eddum*5 dis_*_hh5 disbad_*_hh5 {

local im=substr("`var'",1,length("`var'")-1)

gen `im'dif=.
replace `im'dif=`var'-`im'4

}
 
*Generate cohort by birthyear variables to cluster on
egen coh_prov_clust=group(biryear_impl birprov_impl)

*Regressions

local x rbuc_garefined
local rhsvari oldindoonly
local rhsvaruse _lam0co3dif
local usei grbr
local macrouse `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'

cd "$reploc/results"

*Column 1
reg `x'dif  `macrouse'  inflationdif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, replace label  keep(`macrouse') addtext(\Delta Demographics, o, \Delta Income, o, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 2
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, o, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
					
	
*Column 3
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 4
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 5
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
									
*Column 6	
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
					
*Column 7		
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif, vce(cluster coh_prov_clust)
outreg2 using Table2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
					
		
